<?php
namespace daicuo;

class Tag
{
    // 错误信息
    protected static $error = 'error';
    
    /**
     * 获取错误信息
     * @return mixed
     */
    public function getError()
    {
        return self::$error;
    }
    
    /**
     * 默认字段
     * @param array $data 初始数据 
     * @return array 表单与表格定义的格式
     */
    public function fields($data){
        
        //表单扩展字段自动处理
        $fields = DcFields(config('custom_fields.term_meta'), $data);
        foreach($fields as $key=>$value){
            if( isset($value['filter']) ){
                if(!in_array($value['filter'],['common','tag'])){
                    unset($fields[$key]);
                }
            }
        }
        
        //表单初始化字段
        $fields = DcArrayArgs($fields, [
            'term_id' => [
                'type'            => 'hidden',
                'value'           => $data['term_id'],
                'order'           => 1,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '80',
                'data-width-unit' => 'px',
                'data-sortable'   => true,
                'data-sort-name'  => 'term_id',
                'data-order'      => 'asc',
            ],
            'term_type' => [
                'type'            => 'hidden',
                'value'           => 'tag',
                'order'           => 11,
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'term_name' => [
                'type'            => 'text',
                'value'           => $data['term_name'],
                'order'           => 21,
                'required'        => true,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
            ],
            'term_slug' => [
                'type'            => 'text',
                'value'           => $data['term_slug'],
                'order'           => 31,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
            ],
            'term_parent' => [
                'type'            => 'hidden',
                'value'           => intval($data['term_parent']),
                'order'           => 41,
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'term_status' => [
                'type'            => 'select',
                'value'           => DcEmpty($data['term_status'],'normal'),
                'option'          => ['normal'=>lang('normal'),'hidden'=>lang('hidden')],
                'order'           => 51,
                'data-filter'     => true,
                'data-visible'    => false,
            ],
            'term_status_text' => [
                'order'           => 52,
                'data-title'      => lang('term_status'),
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'term_count' => [
                'order'           => 61,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => '100',
            ],
            'term_order' => [
                'type'            => 'hidden',
                'value'           => intval($data['term_order']),
                'order'           => 71,
                'data-filter'     => true,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => '100',
            ],
            'term_info' => [
                'type'            => 'text',
                'value'           => $data['term_info'],
                'order'           => 81,
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'term_module' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['term_module'],'common'),
                'order'           => 101,
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.admin.table.formatter',
            ],
            'term_controll' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['term_controll'],'tag'),
                'order'           => 111,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.admin.table.formatter',
            ],
            'term_action' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['term_action'],'index'),
                'order'           => 121,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.admin.table.formatter',
            ],
        ]);
        
        return list_sort_by($fields, 'order', 'asc', true);
    }
}